﻿#pragma once
#include"unordered_map.h"
namespace jz
{
	template<class K,class V, class Hash = HashFunc<K>>
	class unordered_map
	{
		struct map_keyoft
		{
			const K& operator()(const pair<K, V>& kv)
			{
				return kv.first;
			}
		};
	public:
		typedef typename opening_hash::HashTable<K, pair<const K, V>, map_keyoft, Hash>::iterator iterator;
		pair<iterator,bool> insert(const pair<K, V>& kv)
		{
			return u_map.Insert(kv);
		}
		iterator find(const K& key)
		{
			return u_map.Find(key);
		}
		bool erase(const K& key)
		{
			return u_map.Erase(key);
		}
		V& operator[](const K& key)
		{
			pair<iterator, bool> ret = insert(make_pair(key, V()));
			return ret.first->second;
		}
		iterator begin()
		{
			return u_map.begin();
		}
		iterator end()
		{
			return u_map.end();
		}
	private:
		opening_hash::HashTable<K, pair<const K,V>, map_keyoft, Hash> u_map;
	};
	void test_map()
	{
		unordered_map<string, int> dict;
		string arr[] = { "苹果","香蕉","西瓜","香蕉","西瓜","苹果","香蕉","草莓","香蕉","草莓" ,"香蕉","西瓜","苹果","香蕉","草莓" };
		for (auto& kv : arr)
		{
			dict[kv]++;
		}
		for (auto& e : dict)
		{
			cout << e.first << ": " << e.second << endl;
		}
		cout << endl;
	}
}